<?php


namespace App\Web\Controller;


use EchoPHP\Http\Request;
use App\Web\Model\MySearch as MySearchModel;

class MySearch extends Controller {
    /**
     * 新增搜索器
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function addSearch(Request $request) {
        $oprId = $this->getLoginId();
        $params = $request->getParam();
        $fileds = [
            'fulltext','jobtext','onlycurcomp', 'cotext', 'jobarea', 'funtype',
            'nearfuntype', 'salarytype', 'salary1', 'salary2','indtype',
            'nearindtype', 'workyear', 'oversea',
            'degree', 'degree985', 'degree211',
            'degreeallday', 'degreeoversea', 'age','graduateschool','graduateyear', 'exparea', 'lang',
            'english', 'gender', 'major',
            'register', 'resumetime', 'jobstatus', 'searchname'
        ];
        $params = array_intersect_key($params,array_flip($fileds));
        $mySearchModel = new MySearchModel();
        $result = $mySearchModel->addSearch($oprId, $params);
        return $this->json($result);
    }

    /**
     * 删除搜索器
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function delSearch(Request $request) {
        $oprId = $this->getLoginId();
        $searchId = $request->getParam('searchid');
        $mySearchModel = new MySearchModel();
        $result = $mySearchModel->deleteSearch($oprId, $searchId);
        return $this->json($result);
    }

    /**
     * 获取搜索器列表
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function getSearch(Request $request) {
        $oprId = $this->getLoginId();
        $mySearchModel = new MySearchModel();
        $list = $mySearchModel->getSearchList($oprId);
        return $this->json(['status' => true, 'message' => '获取成功', 'searchlist' => array_values($list)]);
    }
}